package maven.demo5;

public class Throws {
    public void divide(int one, int two) throws Exception {
        if (two == 0) {
            throw new Exception("两数相除，除数不能为0");
        } else {
            System.out.println("两数相除，结果为: " + one / two);
        }
    }
    // 异常抛出-- 1. 函数自身处理
    public void selfCompute() {
        try {
            divide(5, 0);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }

    // 异常抛出-- 2. 函数抛出异常，反馈给调用者，让上层处理
    public void compute() throws Exception {
        divide(5, 0);
    }
}
